package InterviewTest.q0201_removeDuplicateNodes;

import CommonClass.Common.ListNode;

import java.util.HashSet;
import java.util.Set;

public class Solution_1 {
    public ListNode removeDuplicateNodes(ListNode head) {
        if (head == null) return head;

        ListNode node = head;
        Set<Integer> set = new HashSet<>();
        set.add(head.val);
        while (node.next != null) {
            if (set.contains(node.next.val)) {
                node.next = node.next.next;
            }else {
                set.add(node.next.val);
                node = node.next;
            }
        }
        return head;
    }
}
